package com.hb.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageHelper;
import com.hb.mapper.JobsMapper;
import com.hb.pojo.Jobs;
import com.hb.service.JobsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Api(tags = {"Jobs模块"}, value = "数据字典控制器")
public class JobsController {

    @Autowired
    private JobsMapper jobsMapper;

    @Autowired
    private JobsService jobsService;

    @ApiOperation("mybatis 测试")
    @GetMapping("/getJob/{id}")
    public String getJobById(@PathVariable int id) {
        Jobs jobs = jobsMapper.selectById("AC_ACCOUNT");
        return jobs.toString();
    }
    @GetMapping("/jobs/list")
    public List<Jobs> getJobsList() {
        //int pageNum = 2;
        //int pageSize = 5;
        //PageHelper.startPage(pageNum,pageSize);
        List<Jobs> list = jobsService.list();
        return list;
    }

    @GetMapping("/jobs/list2")
    public List<Jobs> getJobsList2() {
        Page pageParam = new Page(2, 1);
        QueryWrapper<Jobs> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("job_id", "AD_VP");
        List<Jobs> jobs = jobsMapper.selectList(queryWrapper);
        System.out.println("jobs = " + jobs);
        return jobs;
    }

    @GetMapping("/jobs/list3")
    public Page<Jobs> getJobsList3() {
        Page pageParam = new Page(2, 5);
        QueryWrapper<Jobs> queryWrapper = new QueryWrapper<>();
        queryWrapper.ne("job_id", "");
        Page<Jobs> page = jobsService.page(pageParam, queryWrapper);
        //Page<Jobs> page = jobsMapper.selectPage(pageParam, queryWrapper);
        return page;
    }

    @GetMapping("/jobs/list4")
    public Page<Jobs> getJobsList4() {
        Page pageParam = new Page(2, 5);
        QueryWrapper<Jobs> queryWrapper = new QueryWrapper<>();
        queryWrapper.ne("job_id", "");
        Page<Jobs> page = jobsMapper.selectPage(pageParam, queryWrapper);
        return page;
    }
}